<?php
/**
 * Elgg Message board: add message action
 *
 * @package ElggMessageBoard
 */

$message_content = get_input('message_content');
$annotation_id = get_input('annotation_id');

if ($annotation_id && !empty($message_content)) {
	$annotation = elgg_get_annotation_from_id($annotation_id);
	$name = $annotation->name;
	$value = $message_content;
	$value_type = $annotation->value_type;
	$owner_guid = $annotation->owner_guid;
	$access_id = $annotation->access_id;
	$result = update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id);

	if ($result) {
		system_message(elgg_echo("messageboard:updated"));

	} else {
		register_error(elgg_echo("messageboard:failure"));
	}

} else {
	register_error(elgg_echo("messageboard:blank"));
}

forward(REFERER);
